<!-- 自查-审核（公共） -->
<template>
  <view class="list-container">
    <view class="item item-bottom">
      <view class="top-label">
        <view class="requireStarBottom">审核结果</view>
        <view class="rectification">
          <view v-for="(item, index) in rectificationList" :key="index" @click="selectRectification(item)">
            <view :class="lawFlag === item.value ? 'rectification-item-action' : 'rectification-item'">
              {{ item.name }}
            </view>
          </view>
        </view>
      </view>
      <view v-if="lawFlag === '0'" class="info">
        <view class="">
          <view style="display: flex; flex-direction: column;">
            <view class="zheng-gai-zi">审核意见:</view>
            <view class="infoTextArea">
              <uv-textarea :fixed="true" cursor-spacing="50" v-model="reason" maxlength="200" count placeholder="请输入内容"/>
              <view class="fontCount" @click="showSpeech">
                <view>
                  <image :src="imgMinioPath + '/law/yuyin.png'"/>
                </view>
                <view></view>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
    <uv-gap height="80" bg-color="#f6f6f6" />
    <view class="check-bottom-box">
      <button class="sure-button" :disabled="loading" @click.stop="submit()">确认</button>
    </view>
<!--    <speech-recognition ref="refSpeech" @getSpeeckInfo="getSpeeckInfo"/>-->
  </view>
</template>

<script setup>
  import lawItemAPI from '@/api/law/lawItem/lawItem';
  import speechRecognition from '@/packageDailyCheck/components/speechRecognition.vue'; // TODO h5不好使，最后测试
  import {onLoad} from '@dcloudio/uni-app';
  import {ref, reactive, getCurrentInstance, defineProps} from 'vue';
  import config from "@/common/config";
  let imgMinioPath = ref(config.IMG_MINIO_PATH);

  const {proxy} = getCurrentInstance();

  const props = defineProps({
    law: {
      type: Object,
      default: {
        targetId: '',
        targetName: '',
        schoolId: '',
        schoolName: '',
        canteenId: '',
        canteenName: '',
        userId: '',
        userName: '',
        lawDate: '',
        entryType: '',
        lawStatus: '',
        rectifyFlag: 0,
        rectifyStatus: '',
        auditName: '',
        auditDate: null,
        reviewName: '',
        reviewDate: null,
        lawType: '',
        superviseSign: '',
        caterSign: '',
        createOrgName: '',
      },
      required: true
    },
  });

  let loading = ref(false);
  let userInfo = ref(uni.getStorageSync('userInfo'));

  /** 审核结果 */
  const lawFlag = ref('1');
  const reason = ref('');
  const rectificationList = ref([
    {name: '通过', value: '1'},
    {name: '不通过', value: '0'}
  ]);

  // 切换-审核结果
  function selectRectification(item) {
    lawFlag.value = item.value;
  }

  /** 语音输入 */
  const refSpeech = ref();
  const showSpeech = () => {
    refSpeech.value.open();
  };
  function getSpeeckInfo(val) {
    value.value += val;
  }

  /** 确认提交-审核 **/
  const submit = () => {
    console.log('lawFlag.value', lawFlag.value)
    console.log('reason.value', reason.value)
    if (lawFlag.value === '0' && !reason.value) {
      uni.showToast({
        icon: 'none',
        title: '请输入审核意见'
      });
      return;
    }
    loading.value = false;
    uni.showModal({
      title: '温馨提示',
      content: '确定审核该条数据？',
      success: async function (res) {
        if (res.confirm) {
          let form = {
            lawId: props.law.id,
            userId: userInfo.value.userId,
            userName: userInfo.value.user.nickName,
            lawType: '30',
            lawFlag: lawFlag.value,
            reason: reason.value,
          }
          let res = await proxy.http.asyncPost(lawItemAPI.lawItemAdd, form);
          if (res.code === 0) {
            await uni.showToast({icon: 'success', title: '审核成功', duration: 2000});
            loading.value = true;
            setTimeout(() => {
              goBack();
            }, 1000)
          } else {
            await uni.showToast({title: res.msg, icon: 'none'});
          }
        }
      }
    });
  };

  /** 返回上一页 */
  let goBack = async () => {
    uni.$emit("refresh", {});
    await uni.navigateBack();
  };
</script>

<style lang="scss" scoped>
  @import '@/static/css/dailycheck/viewIndex.scss';


  .list-no {
    height: 80vh;
    margin-left: 5%;
    margin-right: 5%;
    border-radius: 20rpx;
    background-color: #fff;
  }

  ::v-deep .requireStarBottom {
    width: 23%;
    position: relative;
  }

  ::v-deep .requireStarBottom:after {
    position: absolute;
    right: 0;
    vertical-align: bottom; //加上星号会上下居中，不加会在上角展示
    content: ' *';
    color: rgba(255, 59, 48, 1);
    font-size: 100%;
  }

  ::v-deep.uv-textarea__field {
    text-align: left !important;
  }

  .rectification {
    display: flex;
    grid-gap: 20rpx;

    .rectification-item-action {
      width: 110rpx;
      height: 60rpx;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #fff;
      background-color: rgba(51, 117, 246, 0.698);
      border-radius: 2px;
      font-size: 24rpx;
    }

    .rectification-item {
      background: #cccccc;
      @extend .rectification-item-action;
    }
  }
  .zheng-gai-zi {
    margin-left: 0;
  }
</style>
